package com.firewolf.spring;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.spring.entities.Dept;
import com.spring.entities.GlobalBean;
import com.spring.entities.User;

/**
 * 
 * @author lx
 *
 */
public class MainDriver {
	
	private ApplicationContext ctx = null;
	
	/**
	 * 初始化
	 */
	@Before
	public void init(){
		ctx = new ClassPathXmlApplicationContext("spring.xml");
	}
	
	/**
	 * 1.属性注入
	 */
	@Test
	public void propertySet(){
		User user = (User) ctx.getBean("user");
		System.out.println(user);
	}
	
	/**
	 * 2.使用P命名空间注入属性
	 */
	@Test
	public void PNameSpace(){
		User user = (User) ctx.getBean("user2");
		System.out.println(user);
	}
	@Test
	public void casadeProperty(){
		Dept dept = (Dept) ctx.getBean("dept");
		System.out.println(dept);
	}
	
	
	@Test
	public void constructor(){
		User user = (User) ctx.getBean("user3");
		System.out.println(user);
	}
	
	@Test
	public void factoryMethod(){
		GlobalBean global = (GlobalBean) ctx.getBean("singleTon");
		global.showMe();
	}
	
}                                                                                     
